package com.xoms.admin.controller.springmvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import com.xoms.admin.controller.res.*;
import com.xoms.admin.controller.res.bean.*;
import com.xoms.admin.controller.springmvc.req.*;

/**
 * 商品库存审核相关接口
 **/
@Controller
@RequestMapping(value = "/audit", produces = "application/json")
public class SProAuditController {
	@Autowired
	com.xoms.admin.controller.ProAuditController proAuditController;

	/**
	 * 获取审核列表
	 **/
	@RequestMapping("/v1/getAudits")
	@ResponseBody
	public ListResult<RProAuditBean> getAudits(@Validated GetProAuditsParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RProAuditBean> res = new ListResult<RProAuditBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proAuditController.getAudits(param, request, response);
	}

	/**
	 * 获取当前账号审核列表
	 **/
	@RequestMapping("/v1/getAudits4Account")
	@ResponseBody
	public ListResult<RProAuditBean> getAudits4Account(@Validated GetProAudits4AccountParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RProAuditBean> res = new ListResult<RProAuditBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proAuditController.getAudits4Account(param, request, response);
	}

	/**
	 * 审核：审核后更新关联信息状态，根据类型更新不同审核内容
	 **/
	@RequestMapping("/v1/audit")
	@ResponseBody
	public BaseResult audit(@Validated ProAuditParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proAuditController.audit(param, request, response);
	}

	/**
	 * 获取采购审核详情
	 **/
	@RequestMapping("/v1/getPurchase")
	@ResponseBody
	public ObjectResult<RAuditPurchaseBean> getPurchase(@Validated GetAuditPurchaseParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RAuditPurchaseBean> res = new ObjectResult<RAuditPurchaseBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proAuditController.getPurchase(param, request, response);
	}

	/**
	 * 获取入库审核详情
	 **/
	@RequestMapping("/v1/getStockIn")
	@ResponseBody
	public ObjectResult<RAuditStockInBean> getStockIn(@Validated GetAuditStockInParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RAuditStockInBean> res = new ObjectResult<RAuditStockInBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proAuditController.getStockIn(param, request, response);
	}

	/**
	 * 获取盘库审核详情
	 **/
	@RequestMapping("/v1/getCheck")
	@ResponseBody
	public ObjectResult<RAuditCheckBean> getCheck(@Validated GetAuditCheckParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RAuditCheckBean> res = new ObjectResult<RAuditCheckBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proAuditController.getCheck(param, request, response);
	}

	/**
	 * 获取退货审核详情
	 **/
	@RequestMapping("/v1/getPureBack")
	@ResponseBody
	public ObjectResult<RAuditPureBackBean> getPureBack(@Validated GetAuditPureBackParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RAuditPureBackBean> res = new ObjectResult<RAuditPureBackBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proAuditController.getPureBack(param, request, response);
	}

	/**
	 * 获取报损审核详情
	 **/
	@RequestMapping("/v1/getBreakage")
	@ResponseBody
	public ObjectResult<RAuditBreakageBean> getBreakage(@Validated GetAuditBreakageParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RAuditBreakageBean> res = new ObjectResult<RAuditBreakageBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return proAuditController.getBreakage(param, request, response);
	}
}
